package com.chixing.day16_io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class OutputStreamDemo {
    public static void main(String[] args) {
        //写入数据到f:/test1/hello.txt
        //1.创建字节写入流
        OutputStream os = null;
        try {
            os = new FileOutputStream("f:/test1/hello.txt");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        //2.写数据
        String content = "Oh bank 你就是我心中的棉花糖 甜蜜的梦想  gkf spuergirls ";
        try {
            os.write(content.getBytes());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {//3.关闭流(释放内存，节约资源)
            if (os!=null) {
                try {
                    os.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }


    }
}
